﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    public void load_Image()
    {
        if (Session["Image"] != null)
        {
            ArrayList arrImage = (ArrayList)Session["Image"];

            repeaterImage.DataSource = arrImage;
            repeaterImage.DataBind();
        }
    }

    protected void btAddImage_Click(object sender, EventArgs e)
    {

        if (Session["Image"] == null)
        {
            if (!String.IsNullOrEmpty(txtImage.Text))
            { 
                ArrayList arrImage = new ArrayList();
                arrImage.Add(txtImage.Text);

                Session["Image"] = arrImage;
                load_Image();            
            }            
        }
        else
        {
            ArrayList arrImage = (ArrayList)Session["Image"];
            

            if (arrImage.Contains(txtImage.Text) == false && String.IsNullOrEmpty(txtImage.Text) != true)
            {
                arrImage.Add(txtImage.Text);
            }

            Session["Image"] = arrImage;
            load_Image();                        
        }
        txtImage.Text = "";
    }
    protected void repeaterImage_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delete")
        {
            string sImage = e.CommandArgument.ToString();

            ArrayList arrImage = (ArrayList)Session["Image"];

            arrImage.Remove(sImage);

            load_Image();
        }
    }

    protected void btSave_Click(object sender, EventArgs e)
    {
        ArrayList arrImage = (ArrayList)Session["Image"];

        string sImageLast = "";
        for (int i = 0; i < arrImage.Count; i++)
        {
            sImageLast += arrImage[i].ToString() + ";\n";
        }

        txtLinkImageLast.Text = sImageLast;
    }
}
